using System;
using System.Collections.Generic;
using System.Text;
using Csla.Data;

namespace MinaspetroLibrary.ProgramacaoPack
{
    [Serializable()]
    public class ProgramacaoChildInfo : Csla.ReadOnlyBase<ProgramacaoChildInfo>
    {
        #region Business Properties and Methods

        //declare members

        private Guid _id = Guid.NewGuid();

        private string _titulo = string.Empty;

        private DateTime _dataEventoInicio = DateTime.Now;

        private DateTime _dataEventoFinal = DateTime.Now;

        private DateTime _dataInscricaoInicio = DateTime.Now;

        private DateTime _dataInscicaoFinal = DateTime.Now;

        private string _datasEvento = string.Empty;

        private bool _inscricaoLiberada = false;

        private string _incricao = string.Empty;

        private string _imagemPrincipal = string.Empty;

        private string _descricao = string.Empty;

        private string _telefones = string.Empty;

        private long _Inscricoes = 0;

        [System.ComponentModel.DataObjectField(true, true)]
        public Guid Id
        {
            get
            {
                return _id;
            }
        }

        public string Inscricoes
        {
            get
            {
                return _Inscricoes.ToString();
            }
        }

        public string Titulo
        {
            get
            {
                return _titulo;
            }
        }

        public DateTime DataEventoInicio
        {
            get
            {
                return _dataEventoInicio;
            }
        }

        public string DataEventoInicioShortString
        {
            get
            {
                return _dataEventoInicio.ToString("dd/MM/yyyy");
            }
        }

        public string DataEventoShortString
        {
            get
            {
                return _dataEventoInicio.ToString("dd/MM/yyyy") + " - " + _dataEventoFinal.ToString("dd/MM/yyyy");
            }
        }

        public string DataEventoInicioFullString
        {
            get
            {
                return _dataEventoInicio.ToString("dd/MM/yyyy HH:mm");
            }
        }

        public DateTime DataEventoFinal
        {
            get
            {
                return _dataEventoFinal;
            }
        }

        public string DataEventoFinalShortString
        {
            get
            {
                return _dataEventoFinal.ToString("dd/MM/yyyy");
            }
        }

        public string DataEventoFinalFullString
        {
            get
            {
                return _dataEventoFinal.ToString("dd/MM/yyyy HH:mm");
            }
        }

        public DateTime DataInscricaoInicio
        {
            get
            {
                return _dataInscricaoInicio;
            }
        }

        public string DataInscricaoInicioShortString
        {
            get
            {
                return _dataInscricaoInicio.ToString("dd/MM/yyyy");
            }
        }

        public string DataInscricaoShortString
        {
            get
            {
                return _dataInscricaoInicio.ToString("dd/MM/yyyy") + " - " + _dataInscicaoFinal.ToString("dd/MM/yyyy");
            }
        }

        public string DataInscricaoInicioFullString
        {
            get
            {
                return _dataInscricaoInicio.ToString("dd/MM/yyyy HH:mm");
            }
        }

        public DateTime DataInscicaoFinal
        {
            get
            {
                return _dataInscicaoFinal;
            }
        }

        public string DataInscicaoFinalShortString
        {
            get
            {
                return _dataInscicaoFinal.ToString("dd/MM/yyyy");
            }
        }

        public string DataInscicaoFinalFullString
        {
            get
            {
                return _dataInscicaoFinal.ToString("dd/MM/yyyy HH:mm");
            }
        }

        public string DatasEvento
        {
            get
            {
                return _datasEvento;
            }
        }

        public bool InscricaoLiberada
        {
            get
            {
                return _inscricaoLiberada;
            }
        }

        public string InscricaoLiberadaString
        {
            get
            {
                if (_inscricaoLiberada)
                    return "InscricaoLiberada";
                return string.Empty;
            }
        }

        public string Incricao
        {
            get
            {
                return _incricao;
            }
        }

        public string ImagemPrincipal
        {
            get
            {
                return _imagemPrincipal;
            }
        }

        public string ImagemPrincipalString
        {
            get
            {
                if (_imagemPrincipal.Contains("_"))
                    return _imagemPrincipal.Substring(_imagemPrincipal.IndexOf("_") + 1);
                return _imagemPrincipal;
            }
        }

        public string Descricao
        {
            get
            {
                return _descricao;
            }
        }

        public string Telefones
        {
            get
            {
                return _telefones;
            }
        }


        protected override object GetIdValue()
        {
            return _id.ToString();
        }

        #endregion //Business Properties and Methods

        #region Authorization Rules
        protected override void AddAuthorizationRules()
        {
            //TODO: Define authorization rules in ProgramacaoChildInfo

        }

        #endregion //Authorization Rules

        #region Factory Methods
        internal static ProgramacaoChildInfo GetProgramacaoChildInfo(SafeDataReader dr)
        {
            return new ProgramacaoChildInfo(dr);
        }

        private ProgramacaoChildInfo(SafeDataReader dr)
        {
            Fetch(dr);
        }
        #endregion //Factory Methods

        #region Data Access

        #region Data Access - Fetch
        private void Fetch(SafeDataReader dr)
        {
            FetchObject(dr);

            //load child object(s)
            FetchChildren(dr);

        }

        private void FetchObject(SafeDataReader dr)
        {
            _id = new Guid(dr["Id"].ToString());
            _titulo = dr.GetString("Titulo");
            _dataEventoInicio = dr.GetDateTime("DataEventoInicio");
            _dataEventoFinal = dr.GetDateTime("DataEventoFinal");
            _dataInscricaoInicio = dr.GetDateTime("DataInscricaoInicio");
            _dataInscicaoFinal = dr.GetDateTime("DataInscicaoFinal");
            _datasEvento = dr.GetString("DatasEvento");
            _inscricaoLiberada = dr.GetBoolean("InscricaoLiberada");
            _incricao = dr.GetString("Incricao");
            _imagemPrincipal = dr.GetString("ImagemPrincipal");
            _descricao = dr.GetString("Descricao");
            _telefones = dr.GetString("Telefones");
            _Inscricoes = dr.GetInt64("Inscricoes");
        }

        private void FetchChildren(SafeDataReader dr)
        {
        }
        #endregion //Data Access - Fetch
        #endregion //Data Access
    }
}
